﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>组织新增</title>
	<jsp:include page="/resources/inc/head.jsp" flush="true"/>
</head>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<body>
<div class="main" style="padding: 20px 5px;">
	<form id="createForm" method="post" class="form-horizontal">
	    <input type="hidden" name="pid" id="parentCode" value="0">
		<div class="form-group col-xs-12">
        		    <div class="col-xs-2">
        			    <label for="name" style="color:#666">机构名称</label>
        			</div>
        			<div class="col-xs-10">
        			<input id="name" type="text" class="form-control" name="name" maxlength="20">
        			</div>
        		</div>
        		<div class="form-group col-xs-12">
                    <div class="col-xs-2">
                        <label for="type" style="color:#666" >机构类型</label>
                    </div>
                    <div class="col-xs-10">
                    <input id="type" type="text" class="form-control" name="type" maxlength="20">
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="col-xs-2">
                        <label for="contactName" style="color:#666" >机构联系人</label>
                    </div>
                    <div class="col-xs-10">
                    <input id="contactName" type="text" class="form-control" name="contactName" maxlength="20">
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="col-xs-2">
                        <label for="contactPhone" style="color:#666" >联系方式</label>
                    </div>
                    <div class="col-xs-10">
                    <input id="contactPhone" type="text" class="form-control" name="contactPhone" maxlength="20">
                    </div>
                </div>
<div class="form-group col-xs-12">
                    <div class="col-xs-2">
                        <label for="latitude" style="color:#666" >地理纬度</label>
                    </div>
                    <div class="col-xs-10">
                    <input id="latitude" type="text" class="form-control" name="latitude" maxlength="20">
                    </div>
                </div>
<div class="form-group col-xs-12">
                    <div class="col-xs-2">
                        <label for="longitude" style="color:#666" >地理经度</label>
                    </div>
                    <div class="col-xs-10">
                    <input id="longitude" type="text" class="form-control" name="longitude" maxlength="20">
                    </div>
                </div>
		<div class="form-group text-right dialog-buttons col-xs-12">
			<a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
			<a class="waves-effect waves-button" id="closeBtn" href="javascript:;">取消</a>
		</div>
	</form>
</div>
<jsp:include page="/resources/inc/footer.jsp" flush="true"/>
<script>
$(function(){
    $("#closeBtn").bind('click',function(){
          close();
    });
});

function close()
{
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

function createSubmit() {
    var parentCode = $("#parentCode" , parent.document).val();
    $("#parentCode").val(parentCode);
    debugger;
    $.ajax({
        type: 'post',
        url: '${basePath}/manage/organization/create',
        data: $('#createForm').serialize(),
        beforeSend: function() {
            if ($('#name').val() == '') {
                $('#name').focus();
                return false;
            }
        },
        success: function(result) {
			if (result.code != 1) {
				if (result.data instanceof Array) {
					$.each(result.data, function(index, value) {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: value.errorMsg,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
					});
				} else {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: result.data.errorMsg,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
				}
			} else {
			        close();
			        window.parent.$table.bootstrapTable('refresh');
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.confirm({
				theme: 'dark',
				animation: 'rotateX',
				closeAnimation: 'rotateX',
				title: false,
				content: textStatus,
				buttons: {
					confirm: {
						text: '确认',
						btnClass: 'waves-effect waves-button waves-light'
					}
				}
			});
        }
    });
}
</script>
</body>